package com.the4man.framework.util.io;

import java.io.*;

/**
 * Created by lenovo on 2017/12/12.
 */
public class FileReadHandler {
    private FileInputStream fileInputStream = null;
    private Reader reader = null;
    private BufferedReader utfRead = null;
    private String filePath = null;

    public FileReadHandler(String filePath) {
        this.filePath = filePath;
    }

    public void open() throws IOException {
        this.fileInputStream = new FileInputStream(this.filePath);
        this.reader = new InputStreamReader(this.fileInputStream, "utf-8");
        this.utfRead = new BufferedReader(this.reader);
    }

    public String readline() throws IOException {
        return this.utfRead.readLine();
    }

    public void close() throws IOException {
        if(this.utfRead != null) {
            this.utfRead.close();
            this.utfRead = null;
        }

        if(this.reader != null) {
            this.reader.close();
            this.reader = null;
        }

        if(this.fileInputStream != null) {
            this.fileInputStream.close();
            this.fileInputStream = null;
        }

    }

    public void delFile() {
        File file = new File(this.filePath);
        if(file.exists()) {
            file.delete();
        }

    }
}